package Demo6;

public class Demo6 {
    public static void main(String[] args) throws InterruptedException {
        Thread t  = new Thread(() -> {
            while(true) {
                System.out.println("新的线程");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"我的线程");

        System.out.println("是否存活: " + t.isAlive());

        //设置为后台进程
        t.setDaemon(true);

        //启动线程
        t.start();

        System.out.println("是否存活: " + t.isAlive());


        for (int i = 0; i < 3; i++) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }

    }
}
